import React from 'react';
import DataTable from 'components/DataTable';
import Icon from 'components/Icon';
import Button from 'components/Button';
import { router } from 'dva';
import moment from 'moment';
const { Link } = router;

export default (self, publishStatus) => [
  {
    title: '试题',
    name: 'name',
    tableItem: {},
    formItem: {
      rules: []
    },
  },{
    title: '类别',
    name: 'type',
    dict: [{code: 2, codeName: '判断题'},{code: 1, codeName: '单选题'}],
    tableItem: {},
    formItem: {rules: []},
  },{
    title: '顺序',
    name: 'orderNo',
    tableItem: {},
  },{
    title: '分数',
    name: 'score',
    tableItem: {},
  },
  {
    title: '选项',
    name: 'options',
    tableItem: {render: (text, record) => {
      if (record.type == 1){
        return record.optionInfos.map(item => <div>{item.optionOrder + '. ' +  item.name}</div> );
      }else{
        return '正确 / 错误';
      }
      }},
  },
  {
    title: '答案',
    name: 'correctAnswer',
    tableItem: {},
  },
  {
    title: '解析',
    name: 'correctAnswerExplain',
    tableItem: {},
  },
  {
    title: '创建时间',
    name: 'createTime',
    tableItem: {
      render: text =>
        moment.utc(text).format('YYYY-MM-DD HH:mm')
    },
  }, {
    title: '操作',
    tableItem: {
      width: 180,
      render: (text, record) => {
        if(publishStatus){
          return <div>试卷已发布，无法修改</div>
        }
        let editBtn;
        if(record.type == 1){
          editBtn = <Button tooltip="修改" onClick={e => self.onAddSelection(record)}>
            <Icon type="edit"/>
          </Button>
        }else{
          editBtn = <Button tooltip="修改" onClick={e => self.onAddTrue(record)}>
            <Icon type="edit"/>
          </Button>
        }

        return <DataTable.Oper>
          {editBtn}
          <Button tooltip="删除" onClick={e => self.onDelete(record)}>
            <Icon type="trash"/>
          </Button>
        </DataTable.Oper>
      }
    }
  }
];

export let selectColumns = (self)=>[
  {
    title: 'ID',
    name: 'id',
    formItem: {'type': 'hidden'}
  },{
    title: '试题',
    name: 'name',
    tableItem: {},
    formItem: {
      type: 'textarea',
      rules: [ {required: true}]
    },
  },{
    title: '顺序',
    name: 'orderNo',
    formItem: { type : 'number',
      rules: [ {required: true}]
    },
  },{
    title: '分数',
    name: 'score',
    formItem: { type : 'number',
      rules: [ {required: true}]
    },
  },{
    title: '选项A',
    name: 'option_a',
    formItem: {rules: [ {required: true}]},
  },{
    title: '选项B',
    name: 'option_b',
    formItem: {rules: [ {required: true}]},
  },{
    title: '选项C',
    name: 'option_c',
    formItem: {},
  },{
    title: '选项D',
    name: 'option_d',
    formItem: {},
  },{
    title: '选项E',
    name: 'option_e',
    formItem: {},
  },{
    title: '选项F',
    name: 'option_f',
    formItem: {},
  },{
    title: '选项G',
    name: 'option_g',
    formItem: {},
  },{
    title: '正确答案',
    name: 'correctAnswer',
    dict: [{code: 'A' , codeName: 'A'},
          {code: 'B' , codeName: 'B'},
          {code: 'C' , codeName: 'C'},
          {code: 'D' , codeName: 'D'},
          {code: 'E' , codeName: 'E'},
          {code: 'F' , codeName: 'F'},
          {code: 'G' , codeName: 'G'}],
    formItem: { type:'select', rules: [ {required: true}]},
  },{
    title: '解析',
    name: 'correctAnswerExplain',
    formItem: {
      type: 'textarea',
      rules: [ {required: true}]
    },
  },
]


export let trueColumns = (self) => [
  {
    title: 'ID',
    name: 'id',
    formItem: {'type': 'hidden'}
  },{
    title: '试题',
    name: 'name',
    tableItem: {},
    formItem: {
      type: 'textarea',
      rules: [ {required: true}]
    },
  },{
    title: '顺序',
    name: 'orderNo',
    formItem: { type : 'number',
      rules: [ {required: true}]
    },
  },{
    title: '分数',
    name: 'score',
    formItem: { type : 'number',
      rules: [ {required: true}]
    },
  },{
    title: '正确答案',
    name: 'correctAnswer',
    dict: [{code: '正确' , codeName: '正确'}, {code: '错误', codeName: '错误'}],
    formItem: { type:'select', rules: [ {required: true}]},
  },{
    title: '解析',
    name: 'correctAnswerExplain',
    formItem: {
      type: 'textarea',
      rules: [ {required: true}]
    },
  },
]
